package cz.muni.fi.cassandra.Playorm.entities;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alvazan.orm.api.base.anno.NoSqlEntity;
import com.alvazan.orm.api.base.anno.NoSqlId;
import com.alvazan.orm.api.base.anno.NoSqlIndexed;
import com.alvazan.orm.api.base.anno.NoSqlOneToMany;

@NoSqlEntity
public class UserPlayorm {
	
	@NoSqlId
    private String id;

    @NoSqlIndexed
    private String name;
    
    // List of users whom user follows
    @NoSqlOneToMany
 	private List<UserPlayorm> following;

 	// List of users who are following user
    @NoSqlOneToMany
 	private List<UserPlayorm> followers;

    @NoSqlOneToMany
 	private List<TweetPlayorm> tweets;

 	public String getId() {
 		return id;
 	}

 	public void setId(String id) {
 		this.id = id;
 	}

 	public List<UserPlayorm> getFollowing() {
 		if (this.following == null) {
 			this.following = new ArrayList<UserPlayorm>();
 		}

 		return Collections.unmodifiableList(this.following);
 	}

 	public void setFollowing(List<UserPlayorm> following) {
 		this.following = null;

 		if (following != null) {
 			this.following = new ArrayList<UserPlayorm>();
 			this.following.addAll(following);
 		}
 	}

 	public List<UserPlayorm> getFollowers() {
 		if (this.followers == null) {
 			this.followers = new ArrayList<UserPlayorm>();
 		}

 		return Collections.unmodifiableList(this.followers);
 	}

 	public void setFollowers(List<UserPlayorm> followers) {
 		this.followers = null;

 		if (followers != null) {
 			this.followers = new ArrayList<UserPlayorm>();
 			this.followers.addAll(followers);
 		}
 	}

 	public List<TweetPlayorm> getTweets() {
 		if (this.tweets == null) {
 			this.tweets = new ArrayList<TweetPlayorm>();
 		}

 		return Collections.unmodifiableList(this.tweets);
 	}

 	public void setTweets(List<TweetPlayorm> tweets) {
 		this.tweets = null;

 		if (tweets != null) {
 			this.tweets = new ArrayList<TweetPlayorm>();
 			this.tweets.addAll(tweets);
 		}
 	}

 	public String getName() {
 		return name;
 	}

 	public void setName(String name) {
 		this.name = name;
 	}
 	
 	@Override
	public String toString() {
		return "User [id=" + id + ", following=" + following + ", followers="
				+ followers + ", tweets=" + tweets + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object object) {
		if (!(object instanceof UserPlayorm)) {
			return false;
		}
		UserPlayorm other = (UserPlayorm) object;
		if ((this.id == null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}
}
